package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.TRole;
import com.dk.service.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.sql.DataSource;
import java.util.List;

@Controller
@RequestMapping("rolecontroller")
public class RoleControoler {
    @Reference
    private RoleService roleService;
    //跳转角色页面
    @RequestMapping("toroleshow")
    public String toroleShow(){
        return "role/show";
    }

    //查询角色
    @RequestMapping("show")
    @ResponseBody
    public List<TRole> selectRole(){
        List<TRole> list = roleService.selectRole();
        return list;
    }

    //跳转角色增加页面
    @RequestMapping("toinsert")
    public String toInsert(){
        return "role/insert";
    }

    //角色增加
    @RequestMapping("insertinto")
    @ResponseBody
    public Boolean insertInto(TRole tRole,Integer[] id){
        Boolean b = roleService.insertRole(tRole,id);
        return b;
    }

    //跳转角色修改界面
    @RequestMapping("toupdate")
    public String toUpdate(Integer rid,Model model){
        //查询当前角色对象
        TRole role = roleService.selectByRid(rid);
        model.addAttribute("role",role);
        return "role/update";
    }

    //角色修改
    @RequestMapping("updateRole")
    @ResponseBody
    public Boolean updateRole(TRole tRole,Integer[] mids){
        Boolean b = roleService.updateRole(tRole,mids);
        return b;
    }

    //角色删除
    @RequestMapping("deleteRole")
    @ResponseBody
    public Boolean deleteRole(Integer id){
        Boolean b = roleService.deleteRole(id);
        return b;
    }

}
